import React from 'react';
import { Router, Route, Switch, Redirect } from 'dva/router';
import Loadable from 'react-loadable';
function Loading () {
  return <div>Loading...</div>;
}

// 组件动态加载
const AuthorRouteComp = Loadable({
  loader: () => import('./pages/author-router'),
  loading: Loading
});

const LoginComp = Loadable({
  loader: () => import('./pages/login'),
  loading: Loading
});

const RegisterComp = Loadable({
  loader: () => import('./pages/register'),
  loading: Loading
});

// 首页
const HomeComp = Loadable({
  loader: () => import('./pages/home'),
  loading: Loading
});
const ChatMessage = Loadable({
  loader: () => import('./components/chat-message'),
  loading: Loading
});
function RouterConfig({ history }) { 
  const routerWhiteList = ['/login', '/register'];
  return (
    <Router history={history}>
      <React.Fragment>
        { !routerWhiteList.includes(history.location.pathname) && <AuthorRouteComp /> }
        <Switch>
          <Route path="/home" component={HomeComp} />
          <Route path="/login" component={LoginComp} />
          <Route path="/register" component={RegisterComp} />
          <Route path="/chat/msg" component={ChatMessage} />
          <Redirect exact from="/" to="/home" />
        </Switch>
      </React.Fragment>
    </Router>
  );
}
export default RouterConfig;
